#pragma once
//============================================================================
// Copyright (C) 2009-2013 Brett R. Jones
//
// Issued to public domain 2013
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include "VxDefs.h"
#include <string>

#pragma pack(push) 
#pragma pack(1)
//! implements unique identifier
//! 16 bytes in size
class OnlineId 
{
public:
	//=== vars ===//
	U64 m_u64IdHiPart;
	U64 m_u64IdLoPart;

	//=== constructor ===//
	OnlineId();
	OnlineId( U64 u64HiPart, U64 u64LoPart );

	//=== methods ===//
	//! copy operator
	OnlineId & operator =( const OnlineId &a );

	//! equals operator
	bool operator == ( const OnlineId &a ) const;

	//! not equal operator
	bool operator != ( const OnlineId &a ) const;

	//! less than operator
	bool operator < ( const OnlineId &b ) const;

	//! return true if valid id
	bool		isOnlineIdValid()	const;
	//! return id as string
	void		toOnlineIdHexString( std::string& strRetId );
	//! set online id by converting hex string into U128
	void		fromOnlineIdHexString( const char * pHexString );
	//! get low part of online id
	U64&		getOnlineIdLoPart();
	//! get high part of online id
	U64&		getOnlineIdHiPart();
	//! return users online id
	OnlineId&	getOnlineId( void );
	void		getOnlineId( std::string& strRetId );
	void		setOnlineId( const char * pId );
	void		setOnlineId( OnlineId& oId );
	void		setOnlineId( U64& u64HiPart, U64& u64LoPart );
	void		getOnlineId( U64& u64HiPart, U64& u64LoPart );

	std::string	describeOnlineId( void );
};
#pragma pack(pop)

//! comparison of online ids for std::map
struct cmp_onlineid 
{
	bool operator()(const OnlineId& a, const OnlineId& b) const
	{
		//! return true if a < b
		return a < b;
	}
};